import { menu } from '../../../app/decorator';
import ShapEllipse from '../shap/ShapEllipse';
import BaseColorShap from './base/BaseColorShap';

const { ccclass, disallowMultiple, executeInEditMode, requireComponent } = cc._decorator;

@ccclass
@menu(__filename, '椭圆形')
@disallowMultiple()
@executeInEditMode()
@requireComponent(ShapEllipse)
export default class ColorShapEllipse extends BaseColorShap {

    constructor() {
        super();

        this._needLineJoin = true;
        this._needMiterLimit = true;
    }

    onLoad() {
        super.onLoad();

        this.node.on('offset-change', this.updateColorShap, this);
        this.node.on('points-change', this.updateColorShap, this);
    }

    onDraw(cxt: cc.Graphics) {
        const polygon = this.getComponent(ShapEllipse);

        const points = polygon.points;

        cxt.moveTo(points[0].x + polygon.offset.x, points[0].y + polygon.offset.y);
        for (let index = 1; index < points.length; index++) {
            cxt.lineTo(points[index].x + polygon.offset.x, points[index].y + polygon.offset.y);
        }
        cxt.close();
    }
}
